import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:ytbusiness/config/icon_list.dart';
import 'package:ytbusiness/config/style.dart';
import 'package:ytbusiness/utils/screen_adaptation.dart';

class AddBankCard extends StatefulWidget {
  @override
  _AddBankCardState createState() => _AddBankCardState();
}

class _AddBankCardState extends State<AddBankCard> {
  int length = 10;

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      onWillPop: () async {
        Navigator.pop(context);
        return false;
      },
      child: Scaffold(
        appBar: AppBar(
          elevation: 1,
          centerTitle: true,
          backgroundColor: Colors.white,
          title: Text(
            "我的银行卡",
            style: TextStyle(
                color: Color(0xff323232),
                fontSize: setSp(18),
                fontWeight: FontWeight.w600),
            maxLines: 1,
            overflow: TextOverflow.ellipsis,
          ),
          leading: GestureDetector(
            behavior: HitTestBehavior.opaque,
            onTap: () {
              Navigator.pop(context);
            },
            child: Row(
              children: [
                Container(
                    margin: EdgeInsets.only(left: setWidth(15)),
                    width: setWidth(10),
                    height: setWidth(17),
                    child: Image.asset(
                      "assets/images/return.png",
                      fit: BoxFit.cover,
                    )),
              ],
            ),
          ),
          actions: [
            GestureDetector(
              behavior: HitTestBehavior.opaque,
              onTap: () {
                Navigator.of(context).pushNamed("bank_card_form").then((value) {
                  if (value != null) {
                    Map val = value as Map;
                  }
                });
              },
              child: Row(
                children: [
                  Container(
                    child: Text("添加银行卡",
                        style: TextStyle(
                            color: Color(0xff197AFF), fontSize: setSp(15))),
                    margin: EdgeInsets.only(right: setWidth(15)),
                  ),
                ],
              ),
            )
          ],
        ),
        body: ListView.builder(
            itemCount: length,
            shrinkWrap: true,
            itemBuilder: (context, index) {
              return Slidable(
                actionPane: SlidableDrawerActionPane(),
                secondaryActions: <Widget>[
                  SlideAction(
                    onTap: () {
                      setState(() {
                        length -= 1;
                      });
                    },
                    color: Color(0xffFF3A31),
                    child: Container(
                      child: Text(
                        "删除",
                        style:
                            TextStyle(color: Colors.white, fontSize: setSp(16)),
                      ),
                    ),
                  ),
                ],
                child: GestureDetector(
                  behavior: HitTestBehavior.opaque,
                  onTap: () {
                    Navigator.pop(context, {
                      "name": "中国农业银行(4747)",
                      "image": IconList.agriculturalBank
                    });
                  },
                  child: Container(
                    decoration: BoxDecoration(
                        color: Colors.white,
                        border: Border(
                            bottom: BorderSide(
                                color: Color(0xffF0F0F0),
                                width: setWidth(0.5)))),
                    padding: EdgeInsets.all(15),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.start,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Container(
                          child: Image.asset(
                            IconList.agriculturalBank,
                            fit: BoxFit.cover,
                          ),
                          width: setWidth(30),
                          height: setWidth(30),
                        ),
                        SizedBox(
                          width: setWidth(12),
                        ),
                        Column(
                          mainAxisAlignment: MainAxisAlignment.start,
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Container(
                              child: Text("中国农业银行",
                                  style: TextStyle(
                                      color: YTStyle.textColor,
                                      fontSize: setSp(16))),
                            ),
                            Container(
                              child: Text("尾号4747",
                                  style: TextStyle(
                                      color: Color(0xff989898),
                                      fontSize: setSp(13))),
                            )
                          ],
                        )
                      ],
                    ),
                  ),
                ),
              );
            }),
      ),
    );
  }
}
